﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using School.Entities;
using School.Common;

namespace School.Pages.Admission
{
    public partial class GradeStudents : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LstCampuses.DataSource = Structure.GetCampuses();
                LstCampuses.DataTextField = "Name";
                LstCampuses.DataValueField = "ID";
                LstCampuses.DataBind();

                LstCertificates.DataSource = Structure.GetCertificatesByCampus(long.Parse(LstCampuses.SelectedValue));
                LstCertificates.DataValueField = "Id";
                LstCertificates.DataTextField = "Name";
                LstCertificates.DataBind();


                LstCertificates.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الشهادة" });
                LstStages.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر المرحلة" });
                LstGrades.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الصف" });
                Panel1.Visible = false;
            }
        }

        protected void LstCampuses_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstCertificates.DataSource = Structure.GetCertificatesByCampus(long.Parse(LstCampuses.SelectedValue));
            LstCertificates.DataValueField = "Id";
            LstCertificates.DataTextField = "Name";
            LstCertificates.DataBind();

            LstCertificates.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الشهادة" });
            Panel1.Visible = false;
        }

        protected void LstCertificates_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstStages.DataSource = Structure.GetStagesByCertificate(long.Parse(LstCertificates.SelectedValue));
            LstStages.DataValueField = "Id";
            LstStages.DataTextField = "Name";
            LstStages.DataBind();
            LstStages.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر المرحلة" });
            Panel1.Visible = false;
        }

        protected void LstStages_SelectedIndexChanged(object sender, EventArgs e)
        {
            LstGrades.DataSource = Structure.GetGradesByStage(long.Parse(LstStages.SelectedValue));
            LstGrades.DataValueField = "Id";
            LstGrades.DataTextField = "Name";
            LstGrades.DataBind();
            LstGrades.Items.Insert(0, new ListItem() { Value = "0", Text = "اختر الصف" });
            Panel1.Visible = false;
        }

        protected void LstGrades_SelectedIndexChanged(object sender, EventArgs e)
        {
            HlReport.NavigateUrl = "Reports/GradeStudentsReport.aspx?Id=" + LstGrades.SelectedValue;

            Panel1.Visible = true;
        }
    }
}